home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group95b.txt / 000012_cargo@ironwood.cray.com _Thu Feb 9 13:23:58 1995.msg < prev    next >
Internet Message Format  |  1995-09-18  |  2KB

  1. Received: from optima.CS.Arizona.EDU by cheltenham.CS.Arizona.EDU; Thu, 9 Feb 1995 12:58:39 MST
  2. Received: from timbuk.cray.com by optima.cs.arizona.edu (5.65c/15) via SMTP
  3.     id AA11254; Thu, 9 Feb 1995 12:58:37 MST
  4. Received: from sdiv.cray.com (ironwood.cray.com [128.162.21.36]) by timbuk.cray.com (8.6.9/CRI-fence-1.4) with SMTP id NAA22970 for <icon-group@cs.arizona.edu>; Thu, 9 Feb 1995 13:24:00 -0600
  5. Received: from fir121 by sdiv.cray.com (5.0/CRI-5.15.b.orgabbr Sdiv)
  6.     id AA03395; Thu, 9 Feb 1995 13:23:59 -0600
  7. From: cargo@ironwood.cray.com (David Cargo)
  8. Received: by fir121 (5.0/btd-b3)
  9.           id AA02772; Thu, 9 Feb 1995 13:23:58 -0600
  10. Message-Id: <9502091923.AA02772@fir121>
  11. Date: Thu, 9 Feb 1995 13:23:58 -0600
  12. To: icon-group@cs.arizona.edu
  13. Subject: string invocation example
  14. X-Mailer: [XMailTool v3.1.0]
  15. Content-Length: 1565
  16.  
  17.  
  18. Of course I found a bug in the code I sent out.  Here's a revised
  19. version.
  20.  
  21. ############################################################################
  22. #
  23. #    File:     filter.icn
  24. #
  25. #    Subject:  Program to apply Icon functions to lines of input
  26. #
  27. #    Author:   David S. Cargo
  28. #
  29. #    Date:     February 9, 1995
  30. #
  31. ############################################################################
  32. #
  33. #    Version:  1.2
  34. #
  35. ############################################################################
  36. #
  37. #   This program uses string invocation to apply an Icon function to lines
  38. #   of input to produce lines of output.  
  39. #
  40. ############################################################################
  41. #
  42. #  Links: none
  43. #
  44. #  Requires: string invocation
  45. #
  46. ############################################################################
  47. invocable all
  48. procedure main(args)
  49.     local arglist, function_name, line
  50.     (*args > 0) | Usage()
  51.     function_name := get(args)
  52.     (function_name == function()) | possible_match(function_name)
  53.     if *args = 0
  54.     then while line := read() do write(function_name(line))
  55.     else
  56.         {
  57.     arglist := [""] ||| args
  58.     while arglist[1] := read() do write(function_name!arglist)
  59.     }
  60.     return
  61. end
  62.  
  63. procedure Usage()
  64.     every write(function())
  65.     stop("Usage: filter functionname [arg1 [arg2 ...]] <stdin >stdout")
  66. end
  67.  
  68. procedure possible_match(function_name)
  69.     local fname
  70.     write(image(function_name), " is not the name of any function.")
  71.     every fname := function() do
  72.         if find(function_name, fname)
  73.         then write(fname)
  74.     stop()
  75. end